package Visao;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import Controle.AlunoControle;
import Controle.ControleFuncionario;
import Modelo.Aluno;
import Modelo.Funcionario;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;

public class Excluir extends JFrame {

	private JPanel contentPane;
	private JComboBox comboBoxAluno;
	private JButton btnListar;
	private JButton button;
	private JButton btnExcluir;
	private JComboBox comboBoxFunci;
	private JButton button_1;
	private AlunoControle controleAluno;
	private Aluno aluno;
	private ControleFuncionario controleFuncionario;
	private Funcionario funcionario;
	private JPanel panel;
	private JPanel panel_1;
	private JLabel lblNewLabel;

	/**
	 * Launch the application.
	 */


	/**
	 * Create the frame.
	 */
	public Excluir() {
		controleFuncionario = new ControleFuncionario();
		controleAluno = new AlunoControle();
		setTitle("Excluir");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 451, 300);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		panel = new JPanel();
		panel.setBackground(new Color(0, 139, 139, 50));
		panel.setBounds(66, 21, 313, 113);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblAluno = new JLabel("ALUNO");
		lblAluno.setBounds(10, 11, 46, 14);
		panel.add(lblAluno);
		lblAluno.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
		
		comboBoxAluno = new JComboBox();
		comboBoxAluno.setBounds(10, 36, 186, 22);
		panel.add(comboBoxAluno);
		
		btnListar = new JButton("Listar");
		btnListar.setBounds(206, 36, 91, 23);
		panel.add(btnListar);
		
		btnExcluir = new JButton("Excluir");
		btnExcluir.setBounds(206, 70, 91, 23);
		panel.add(btnExcluir);
		
		panel_1 = new JPanel();
		panel_1.setBackground(new Color(0, 139, 139, 50));
		panel_1.setBounds(66, 149, 313, 113);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblFuncionario = new JLabel("FUNCIONARIO");
		lblFuncionario.setBounds(10, 11, 91, 14);
		panel_1.add(lblFuncionario);
		lblFuncionario.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 11));
		
		comboBoxFunci = new JComboBox();
		comboBoxFunci.setBounds(10, 35, 186, 22);
		panel_1.add(comboBoxFunci);
		
		button_1 = new JButton("Excluir");
		button_1.setBounds(206, 69, 91, 23);
		panel_1.add(button_1);
		
		button = new JButton("Listar");
		button.setBounds(206, 35, 91, 23);
		panel_1.add(button);
		
		lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon("H:\\workspace\\SupportWatchful\\Imagens\\i=magem lois.jpg"));
		lblNewLabel.setBounds(0, 0, 443, 273);
		contentPane.add(lblNewLabel);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				comboBoxAluno.removeAllItems();
				for(Funcionario funcionario : controleFuncionario.listar()){
					comboBoxAluno.addItem(funcionario);
				}
			}
		});
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				funcionario = (Funcionario) comboBoxFunci.getSelectedItem();
				
				try {
					controleFuncionario.deletar(funcionario);
					comboBoxFunci.removeItem(funcionario);
					JOptionPane.showMessageDialog(null, "Funcionario deletado!!");
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}
		});
		btnExcluir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				aluno = (Aluno) comboBoxAluno.getSelectedItem();
				try {
					controleAluno.excluir(aluno);
					comboBoxAluno.removeItem(aluno);
					JOptionPane.showMessageDialog(null, "Aluno deletado");
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}
		});
		btnListar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				comboBoxAluno.removeAllItems();
				for(Aluno aluno : controleAluno.listar()){
					comboBoxAluno.addItem(aluno);
				}
				
				
			}
		});
	}
}
